package com.foreknow.protals.controller;

import com.foreknow.protals.common.api.CommonPage;
import com.foreknow.protals.common.api.CommonResult;
import com.foreknow.protals.dto.PmsBrandDto;
import com.foreknow.protals.mbg.model.PmsBrand;
import com.foreknow.protals.service.PmsBrandService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "PmsBrandController",description = "商品品牌管理")
@Controller
@RequestMapping("/brand")
public class PmsBrandController {
    private static final Logger LOGGER = LoggerFactory.getLogger(PmsBrandController.class);
    @Autowired
    private PmsBrandService brandService;

    @ApiOperation("获取所有品牌列表")
    @RequestMapping(value = "listAll",method = RequestMethod.GET)
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('pms:brand:read')")
    public CommonResult<List<PmsBrand>> getBrandList() {
        return CommonResult.success(brandService.listAllBrand());
}

//    @ApiOperation("分页查询品牌列表")
//    @RequestMapping(value = "list",method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<CommonPage<PmsBrand>> listBrand(@RequestParam(value = "keyword",required = false)String keyword,
//                                                        @RequestParam(value = "pageNum",defaultValue = "1") @ApiParam("页码") int pageNum,
//                                                        @RequestParam(value = "pageSize",defaultValue = "3") @ApiParam("每页数量")int pageSize) {
//        List<PmsBrand> brandList = brandService.listBrand(keyword,pageNum,pageSize);
//        return CommonResult.success(CommonPage.restPage(brandList));
//    }
//
//    @ApiOperation("根据id查询品牌的详细信息")
//    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
//        return CommonResult.success(brandService.getBrand(id));
//    }
//
//    @ApiOperation("根据id删除某个品牌信息")
//    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
//    @ResponseBody
//    public CommonResult deleteBrand(@PathVariable("id")Long id) {
//        int count = brandService.deleteBrand(id);
//        if(count == 1) {
//            return CommonResult.success(null);
//        }else {
//            return CommonResult.failed("操作失败");
//        }
//    }
//    @ApiOperation("添加品牌信息")
//    @RequestMapping(value = "/create",method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult create(@Validated @RequestBody PmsBrandDto pmsBrandDto) {
//        int isRight = brandService.createBrand(pmsBrandDto);
//        CommonResult commonResult = null;
//        if(isRight==1) {
//            commonResult = CommonResult.success(isRight);
//        }else {
//            commonResult = CommonResult.failed("");
//        }
//        return commonResult;
//    }
}
